//
//  TMListView.m
//  国学商家管理
//
//  Created by Tao Li on 2018/6/23.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMListView.h"
#import "TMListDetailCell.h"
#import "TMComplainCell.h"
//#import "TMCourseModel.h"
#import "TMFinanceModel.h"
//#import "TMTeacherModel.h"
@interface TMListView()<UITableViewDelegate, UITableViewDataSource>

@end
@implementation TMListView
-(void)awakeFromNib{
    [super awakeFromNib];
    self.listTab.delegate = self;
    self.listTab.dataSource = self;
    [self.listTab registerNib:[UINib nibWithNibName:@"TMListDetailCell" bundle:nil] forCellReuseIdentifier:@"TMListDetailCell"];
    [self.listTab registerNib:[UINib nibWithNibName:@"TMComplainCell" bundle:nil] forCellReuseIdentifier:@"TMComplainCell"];
    self.listTab.separatorStyle = UITableViewCellSeparatorStyleNone;
}
-(void)setIsTeacher:(BOOL)isTeacher{
    _isTeacher = isTeacher;
}
-(void)setIsCourse:(BOOL)isCourse{
    _isCourse = isCourse;
    if (_isCourse == NO) {
        self.titleLabel.hidden = YES;
        self.greenView.hidden= YES;
        self.moreRecodBtn.hidden = YES;
        self.topConst.constant = 0;
        self.leftConst.constant = 0;
        self.rightConst.constant = 0;
    }else{
        self.titleLabel.hidden = NO;
        self.greenView.hidden= NO;
        self.moreRecodBtn.hidden = NO;
        self.topConst.constant = 65;
        self.leftConst.constant = 17;
        self.rightConst.constant = 17;
    }
}
- (void)setIsStarsShow:(BOOL)isStarsShow{
    _isStarsShow = isStarsShow;
    if (_isStarsShow == YES) {
        self.titleLabel.text = @"评级记录";
    }else{
    self.titleLabel.text = @"授课记录";
    }
}
- (void)setIsFanical:(BOOL)isFanical{
    _isFanical = isFanical;
}
- (void)setList:(NSArray *)list{
    _list = list;
    [self.listTab reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.isCourse == YES) {
        TMListDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TMListDetailCell" forIndexPath:indexPath];
        cell.isStarsShow = _isStarsShow;
        if (self.isTeacher == YES) {
            TMTeacherRecordsModel *model = self.list[indexPath.row];
            cell.deltailModel = model;
        }else{
        TMCourseRecordsModel *model = self.list[indexPath.row];
        cell.model = model;
        }
        return cell;
    }else{
        TMComplainCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TMComplainCell" forIndexPath:indexPath];
        cell.isUserManage = NO;
        cell.isFanincal = self.isFanical;
        if (self.isFanical == YES) {
            BOOL isuse = [[NSUserDefaults standardUserDefaults] boolForKey:@"isuse"];
            if (isuse == NO) {
                cell.userName.text = [NSString stringWithFormat:@"成功邀请%@获得 %.02f 元奖励,详情请查看账单",self.list[indexPath.row][@"username"], [self.list[indexPath.row][@"price"]floatValue]];
            }else{
           cell.userName.text = [NSString stringWithFormat:@"%@消费活动 %.02f 元奖励,详情请查看账单",self.list[indexPath.row][@"username"], [self.list[indexPath.row][@"price"]floatValue]];
            }
//            //@"成功邀请XXX获得 80 元奖励,详情请查看账单";
            cell.handleLabel.text = @"";
        }else{
            TMFinanceModel *fmodel = self.list[indexPath.row];
            cell.faincalModel1 = fmodel;
        }
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.isCourse == YES) {
//        if (self.isTeacher == YES) {
//            TMTeacherRecordsModel *model = self.list[indexPath.row];
//            [[NSNotificationCenter defaultCenter] postNotificationName:@"JOINCOURSEDETAILNOTI" object:nil userInfo:@{@"teid":@(model.cid)}];
//        }else{
//        TMCourseRecordsModel *model = self.list[indexPath.row];
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"JOINCOURSEDETAILNOTI" object:nil userInfo:@{@"teid":@(model.te_id)}];
//    }
    }else{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"JOINCOURSEDETAILNOTI" object:nil];
    }
}
@end
